import { Form, InputNumber, Modal } from "antd";
import React from "react";

class DealtwithTimes extends React.Component{
  constructor(props){
    super(props);
    this.state = {
      visible:false,
      type:"",
      params:null
    }
  }

  componentDidMount(){
    if(this.props.onRef){
      this.props.onRef(this)
    }
  }

  initModal = (type,params) => {
    this.setState({
      type,
      visible:true,
      params
    })
  }

  validateForm = () => {
    this.props.form.validateFields((error,values) => {
      if(!error){
        this.props.getSolutionDuration(values.solutionDuration,this.state)
        this.doCancel()
      }
    })
  }

  doCancel = () => {
    this.props.form.resetFields()
    this.setState({visible:false})
  }

  render(){
    const { visible,type } = this.state;
    const { form:{getFieldDecorator} } = this.props;
    return (
      <Modal
        title={type == 'workOrderInfo' ? "本次处理工时" : '确认关闭工单'}
        okText="确定"
        cancelText="取消"
        onOk={this.validateForm}
        onCancel={this.doCancel}
        visible={visible}
        okType={type == 'workOrderInfo' ? "primary" : 'danger'}
      >
        <Form layout="inline">
          <Form.Item label="本次处理工时">
            {
              getFieldDecorator('solutionDuration',{initialValue:0.5,rules:[{required:true,message:"请输入"}]})(
                <InputNumber min={0} precision={1} step={0.5} />
              )
            }
          </Form.Item>
          {
            type == 'workOrderInfo' ? '' : (
              <Form.Item label=' ' colon={false}>
                <span style={{color:"red"}}>工单关闭后用户无法再次提问，请确认是否关闭</span>
              </Form.Item>
            )
          }
          
        </Form>
      </Modal>
    )
  }
}

export default Form.create()(DealtwithTimes)